/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.graphic;

import Modelos.*;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import ui.graphic.maps.MapDataModel;
import ui.graphic.maps.MapData;
import javax.sound.sampled.LineUnavailableException;
import javax.swing.JFrame;
import logicGame.Game;
import logicGame.States.And;
import logicGame.States.Auction;
import logicGame.States.BuyCard;
import logicGame.States.Or;
import logicGame.States.PickArmy;
import logicGame.States.PickPlace;
import logicGame.States.Setup;
import logicGame.States.State;
import ArtificialInteligence.Ia;

/**
 *
 * @author Abyssus
 */
public class MainGUI implements Observer {
    Ia IntArt;
    MapDataModel model;
    MapData data;
    ModeloTabuleiro mT;
    ModeloCartas mC;
    SplashScreen sP;
    FinalFrame fim;
    Frame f;
    private Game game;

    void run() throws LineUnavailableException {
        game = new Game();
        mT = new ModeloTabuleiro(game);
        mC = new ModeloCartas(game);
        data = new MapData();
        model = new MapDataModel(data);
//        f = null;
        sP = null;

        mC.addObserver(this);
        mT.addObserver(this);

        State state = game.getState();
        if (state instanceof Setup) {
            sP = new SplashScreen(mT);
        }

        IntArt = new Ia(mT, mC);

    }

    @Override
    public void update(Observable o, Object arg
    ) {
        State state = game.getState();
        if (state == null) {
            f.setVisible(false);
            fim = new FinalFrame(mT);

        } else if (state instanceof Setup) {
            sP = new SplashScreen(mT);

        } else if (state instanceof Auction) {
            sP.fazBet();
            sP.setVisible(false);

        } else if (state instanceof BuyCard) {
            if (f == null) {
                try {
                    f = new Frame("Eight Minute Empire", 0, 0, 1280, 715, data, model, mT, mC);

                } catch (LineUnavailableException ex) {
                }
            }
            f.setVisible(true);
            f.setExtendedState(JFrame.MAXIMIZED_BOTH);
            
        } else if (state instanceof PickPlace) {

        } else if (state instanceof PickArmy) {

        } else if (state instanceof And) {
            f.setVisible(false);
            f.andCardPopUp();
            f.setVisible(true);
            f.setExtendedState(JFrame.MAXIMIZED_BOTH);
        } else if (state instanceof Or) {
            f.setVisible(false);
            f.orCardPopUp();
            f.setVisible(true);
            f.setExtendedState(JFrame.MAXIMIZED_BOTH);
        }
    }
}
